﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QXBook.Utils;

namespace Web.SysManage.ctrl
{
    public partial class ListMenuCtrl : System.Web.UI.UserControl
    {
        public event EventHandler AddHandler;
        public event EventHandler EditHandler;
        public event EventHandler PublishHandler;
        public event EventHandler NoPublishHandler;
        public event EventHandler ShipmentHandler;
        public event EventHandler ReSaveHandler;
        public event EventHandler DeleteHandler;
        public event EventHandler RefinshHandler;

        public string AddEditLinkUrl
        {
            get { return ViewState["AddEditLinkUrl"] == null ? string.Empty : CommonUtils.ToString(ViewState["AddEditLinkUrl"]); }
            set { ViewState["AddEditLinkUrl"] = value; }
        }

        #region Enable控件
        public bool EnableLinkNew
        {
            get { return aNew.Visible; }
            set { aNew.Visible = value; }
        }

        public bool EnableLinkEdit
        {
            get { return aEdit.Visible; }
            set { aEdit.Visible = value; }
        }

        public bool EnableLinkPublish
        {
            get { return aPublish.Visible; }
            set { aPublish.Visible = value; }
        }

        public bool EnableLinkOn
        {
            get { return aOn.Visible; }
            set { aOn.Visible = value; }
        }

        public bool EnableLinkOff
        {
            get { return aOff.Visible; }
            set { aOff.Visible = value; }
        }

        public bool EnableLinkShipments
        {
            get { return aShipments.Visible; }
            set { aShipments.Visible = value; }
        }

        public bool EnableLinkDel
        {
            get { return aDel.Visible; }
            set { aDel.Visible = value; }
        }

        public bool EnableLinkResave
        {
            get { return aResave.Visible; }
            set { aResave.Visible = value; }
        }

        public bool EnableLinkRef
        {
            get { return aRef.Visible; }
            set { aRef.Visible = value; }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            aNew.ServerClick += new EventHandler(aNew_ServerClick);
            aEdit.ServerClick += new EventHandler(aEdit_ServerClick);
            aPublish.ServerClick += new EventHandler(Publish_Method);
            aOn.ServerClick += new EventHandler(Publish_Method);
            aOff.ServerClick += new EventHandler(NoPublish_Method);
            aShipments.ServerClick += new EventHandler(aShipments_ServerClick);
            aResave.ServerClick += new EventHandler(aResave_ServerClick);
            aDel.ServerClick += new EventHandler(aDel_ServerClick);
        }

        void aNew_ServerClick(object sender, EventArgs e)
        {
            if (AddHandler != null)
            {
                AddHandler.Invoke(sender, e);
            }
            else if (!string.IsNullOrEmpty(AddEditLinkUrl))
            {
                Response.Redirect(AddEditLinkUrl);
            }
        }

        void aEdit_ServerClick(object sender, EventArgs e)
        {
            if (EditHandler != null)
            {
                EditHandler.Invoke(sender, e);
            }
        }

        void Publish_Method(object sender, EventArgs e)
        {
            if (PublishHandler != null)
            {
                PublishHandler.Invoke(sender, e);
            }
        }

        void NoPublish_Method(object sender, EventArgs e)
        {
            if (NoPublishHandler != null)
            {
                NoPublishHandler.Invoke(sender, e);
            }
        }

        void aShipments_ServerClick(object sender, EventArgs e)
        {
            if (ShipmentHandler != null)
            {
                ShipmentHandler.Invoke(sender, e);
            }
        }

        void aResave_ServerClick(object sender, EventArgs e)
        {
            if (ReSaveHandler != null)
            {
                ReSaveHandler.Invoke(sender, e);
            }
        }

        void aDel_ServerClick(object sender, EventArgs e)
        {
            if (DeleteHandler != null)
            {
                DeleteHandler.Invoke(sender, e);
            }
        }
    }
}